package com.wuchao.service.userserviceImpl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.wuchao.entity.User;
import com.wuchao.mapper.UserMapper;
import com.wuchao.service.UserService;
import com.wuchao.util.Util;
import jdk.nashorn.internal.ir.CallNode;
import org.apache.ibatis.session.SqlSession;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author wuchao66
 * @Date 2022/6/27 16:24
 * @Version 1.0
 */
@Service//这里必须写，证明是实现类
public class UserServiceImpl implements UserService {
    //private SqlSession sqlSession= Util.openSqlsession();
    //Spring
    @Resource //自动注入
    private UserMapper userMapper;

    @Override
    public int deleteUserById(int id) {

        return userMapper.deleteUserById(id);
    }

    @Override
    public PageInfo<User> findUserListByPage(int currentPage, int pageSize,String name) {
        PageHelper.startPage(currentPage,pageSize);//这句话必须是在第一个
        List<User> userList = userMapper.findUserByName(name);
        PageInfo<User> userPageInfo = new PageInfo<>(userList);
        return userPageInfo;
    }

    @Override
    public List<User> findUserList() {
        return userMapper.findUserList();
    }
}
